/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AsigCasoEstudiante.java
 *
 * Created on 22/07/2011, 02:51:12 AM
 */

package Asignaciones;

import ClasesVarias.MiModelo;
import callProcs.ProcsAlumno;
import callProcs.ProcsInsertar;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Javier
 */
public class AsigCasoEstudiante extends javax.swing.JFrame {
ProcsAlumno caso = new ProcsAlumno();
ProcsInsertar VerEst =new ProcsInsertar();
java.sql.ResultSet rs;
List lista = new ArrayList();        
        Integer cont=0;
        Integer indice=0;
    /** Creates new form AsigCasoEstudiante */
    public AsigCasoEstudiante() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        labelencabezado = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        t_Carne = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        t_Folio = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField4 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jButton1.setText("Asignar Caso A estudiante");
        jButton1.setEnabled(false);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        labelencabezado.setFont(new java.awt.Font("Tahoma", 1, 18));
        labelencabezado.setText("Asignaciones Caso a Estudiante");

        jLabel1.setText("Carne");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("Seleccionar Estudiante");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("Buscar Caso");

        t_Carne.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                t_CarneKeyReleased(evt);
            }
        });

        jLabel4.setText("No. Folio");

        t_Folio.setEnabled(false);

        jButton2.setText("Seleccionar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Asunto", "Cliente", "Descripcion", "Fecha Inicio"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setEnabled(false);
        jScrollPane1.setViewportView(jTable1);

        jTextField4.setEditable(false);

        jLabel7.setText("Nombre");

        jTextField3.setEditable(false);

        jLabel8.setText("Apellido");

        jButton3.setText("Buscar Caso");
        jButton3.setEnabled(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel5.setText("Detalles Caso");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(206, 206, 206)
                        .add(jLabel3))
                    .add(layout.createSequentialGroup()
                        .add(122, 122, 122)
                        .add(labelencabezado, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 310, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(247, 247, 247)
                        .add(jLabel2))
                    .add(layout.createSequentialGroup()
                        .add(50, 50, 50)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(4, 4, 4)
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                            .add(org.jdesktop.layout.GroupLayout.LEADING, jComboBox1, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .add(org.jdesktop.layout.GroupLayout.LEADING, t_Carne, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)))
                                    .add(layout.createSequentialGroup()
                                        .add(jLabel4)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(t_Folio, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 123, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .add(61, 61, 61)
                                        .add(jButton3))
                                    .add(layout.createSequentialGroup()
                                        .add(57, 57, 57)
                                        .add(jButton2)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 234, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .add(8, 8, 8)
                                .add(jLabel7)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 66, Short.MAX_VALUE)
                                .add(jLabel8)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 167, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(82, 82, 82))))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel5))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 608, Short.MAX_VALUE)))
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(381, Short.MAX_VALUE)
                .add(jButton1)
                .add(62, 62, 62))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(labelencabezado, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(20, 20, 20)
                .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(t_Carne, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton2))
                .add(18, 18, 18)
                .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(39, 39, 39)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel8)
                    .add(jLabel7))
                .add(97, 97, 97)
                .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(t_Folio, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton3))
                .add(26, 26, 26)
                .add(jLabel5)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 139, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(37, 37, 37)
                .add(jButton1)
                .addContainerGap(71, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            int indice=jTable1.getSelectedRow();
            String ind=String.valueOf(indice);
            String carne=null;
            carne=jComboBox1.getSelectedItem().toString(); 
            String idcaso="";
            idcaso=lista.get(indice).toString(); 
            
            
            caso.Caso_est(carne,idcaso);
            cont=0;
            JOptionPane.showMessageDialog(null,"Se ha asignado caso exitosamente");
                    
            
        } catch (SQLException ex) {
            Logger.getLogger(AsigCasoEstudiante.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
}//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
         if (jComboBox1.getItemCount()==0){
            JOptionPane.showMessageDialog(null, "Debe Seleccionar el Carne de el Alumno");
        }else{
            
            //codigo de consulta de alumno
            int Carne = Integer.parseInt(jComboBox1.getSelectedItem().toString());
             ProcsInsertar VerEst =new ProcsInsertar();
        try {
            java.sql.ResultSet rs= VerEst.verdatosAlumnos(Carne);
            while (rs.next()){
                jTextField3.setText(rs.getObject("Nombre_estudiante").toString());
                jTextField4.setText(rs.getObject("Apellido_estudiante").toString());
            }
        } catch (SQLException ex) {
            Logger.getLogger(AsigAsesorEstudiante.class.getName()).log(Level.SEVERE, null, ex);
        }
            
            
            jTable1.setEnabled(true);
            t_Folio.setEnabled(true);
            jButton3.setEnabled(true);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void t_CarneKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_CarneKeyReleased
        // TODO add your handling code here:
         jComboBox1.removeAllItems();
       // JOptionPane.showMessageDialog(null, jTextField5.getText());
        try {
           rs= VerEst.verAlumnos(t_Carne.getText());
            while (rs.next()){
                jComboBox1.addItem(rs.getObject("NoCarne"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(AsigAsesorEstudiante.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }//GEN-LAST:event_t_CarneKeyReleased

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        String id="";
    if(!t_Folio.getText().equals("")){
    Vector tableData = new Vector();
    Vector<String> tableHeaders = new Vector<String>();
    
    tableHeaders.add("Asunto"); 
    tableHeaders.add("Cliente");
    tableHeaders.add("Descripcion");
    tableHeaders.add("Fecha Inicio");
    
    
     Vector<Object> oneRow = null; 
        
        try {
          rs= caso.VerDataCaso(t_Folio.getText());
            while (rs.next()){
                if (rs.getObject("Estudiante_NoCarne") == null) {
                    String As=rs.getObject("NombreAsunto").toString();
                    String cl=rs.getObject("nombrec").toString();
                    String Des=rs.getObject("Descripcion_caso").toString();
                    String fec=rs.getObject("Fecha_inicio").toString();
                
                    oneRow = new Vector<Object>();
                    oneRow.add(As);
                    oneRow.add(cl);
                    oneRow.add(Des);
                    oneRow.add(fec);
        
                    tableData.add(oneRow);
                    id=rs.getObject("idCaso").toString();
                    lista.add(cont,id);
                 //JOptionPane.showMessageDialog(null, lista.get(cont).toString());
                    cont++; 
                }
 
    }
    //jTable2.setModel(new DefaultTableModel(tableData, tableHeaders));
    //MiModelo modelo = new MiModelo();
    jTable1.setModel(new MiModelo(tableData, tableHeaders));  
    jButton1.setEnabled(true);
    
    
        } catch (SQLException ex) {
            Logger.getLogger(AsigCasoEstudiante.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }else JOptionPane.showMessageDialog(null, "Debe Ingresar un Numero de folio");            
        
        
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AsigCasoEstudiante().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JLabel labelencabezado;
    private javax.swing.JTextField t_Carne;
    private javax.swing.JTextField t_Folio;
    // End of variables declaration//GEN-END:variables

}
